package br.ufla.pgcc.oomeasures;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.dom.CompilationUnit;

public class ASTSession {
	private static ASTSession ast;
	private Map<ITypeRoot, CompilationUnit> units;
	
	private ASTSession() {
		units = new HashMap<ITypeRoot, CompilationUnit>();
	}
	
	public static ASTSession getInstance(){
		if (ast == null) {
			ast = new ASTSession();
		}
		return ast;
	} 
	
	public void save(CompilationUnit unit){
		units.put(unit.getTypeRoot(), unit);
	}

	public CompilationUnit get(ITypeRoot unit){
		return units.get(unit);
	}
	
	public boolean contains(ITypeRoot unit){
		return units.containsKey(unit);
	}
	
	public void reset(){
		units.clear();
	}
}
